<template>
  <div class="search">
    <form action="/">
      <van-search v-model="value" placeholder="请输入搜索关键词" show-action @search="onSearch" />
    </form>
    <cinema-list v-if="$route.query.searchtype==='cinema'" :cinemas="cinemas" />
    <movie-list v-else :movieList="movieList" />
  </div>
</template>
<script>
import CinemaList from '../../components/CinemaList'
import MovieList from '../../components/movieList/index'
export default {
  data: () => ({
    value: '',
    cinemas: [],
    movieList: []
  }),
  created () {
    this.$store.state.bottomFlag = false
    this.$store.state.topFlag = true
  },
  methods: {
    async onSearch () {
      let data
      if (this.$route.query.searchtype === 'movie') {
        data = await this.$http.get('ajax/search?kw=' + this.value + '&cityId=' + this.$store.state.cityId + '&stype=-1')
        console.log(data)
        this.movieList = data.data.movies.list
        console.log(1)
      } else {
        data = await this.$http.get('ajax/search?kw=' + this.value + '&cityId=' + this.$store.state.cityId + '&stype=2')
        this.cinemas = data.data.cinemas.list
        console.log(2)
      }
      console.log(this.movieList)
    }
  },
  components: {
    CinemaList,
    MovieList
  }
}
</script>
<style lang="less" scoped>
</style>
